<template>
<a-input-search v-model="seletedValue" :disabled="disabled" :placeholder="placeholder" enter-button  @search="inputOnSearch" />
  <!-- <a-select
    style="width:100%;"
    showSearch
    allowClear
    :disabled="disabled"
    :filterOption="filterOption"
    :placeholder="placeholder"
    @change="handleChange"
    :value="seletedValue"
  >
    <a-select-option
      v-for="(item) in orgs"
      :key="item.pid">
      {{ item.orgName }}
    </a-select-option>
  </a-select> -->
</template>

<script>
import { getOrgInfoByIdno } from '../org/org/org'
import storage from 'store'

export default {
  name: 'OrgSearch',
  props: {
    placeholder: {
      default: '请选择单位',
      required: false,
      type: String
    },
    disabled: {
      default: false,
      required: false,
      type: Boolean
    },
    value: {
      default: '',
      required: false,
      type: String
    }
  },
  data () {
    return {
      org: storage.get('org'),
      orgs: [],
      seletedValue: ''
    }
  },
  created () {
  },
  methods: {
    async inputOnSearch () {
      const parameter = this.seletedValue
      const r = await getOrgInfoByIdno(parameter, {})
      if (r && r && r.code === 'C1' && r.data) {
        console.log(r.data)
        const result = {
          orgIdno: this.seletedValue,
          org : r.data 
        }
        this.$emit('search', result)
      }else{
        this.$message.error({ content: '查询失败，请检查输入内容是否正确！', duration: 2})
      }
    }
  },
  watch: {
    value: function () {
      this.seletedValue = this.value
    }
  }
}
</script>
